<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    [#include "/includes/header.html" /]
    <style type="text/css">
        .col-md-5 select {
            width: 30%;
            float: left;
        }
    </style>
</head>
<body class="fixed-sidebar full-height-layout gray-bg">
[#include "/includes/menus.html" /]
<div class="wrapper wrapper-content">
    <div class="row content-tabs">
        <nav class="page-tabs J_menuTabs">
            <div class="page-tabs-content" style="margin-left: 0px;">
                <a href="${webctx}/commission" class="J_menuTab">分销商佣金</a>
                <a href="${webctx}/commission/rate" class="J_menuTab active">佣金设置</a>
            </div>
        </nav>
    </div>

    <div class="row">
        <div class="col-sm-9">
            <div class="row ibox-content" id="rateForm">
                <div class="alert alert-success">
                    <i class="fa fa-info-circle"></i><strong>提示:</strong>
                    <p>三级佣金比例累计不可以超过订单金额的50%。</p>
                </div>

                <form name="rateForm" action="" method="post" class="form-horizontal" style="padding-top: 10px;">
                    <div>
                        <input type="hidden" id="rate_id" name="rate_id" value="${rate.id}"/>
                        <div class="form-group">
                            <label class="col-md-3 control-label">直属上级佣金比例：<span
                                    style="color: red;"><em>*</em></span></label>
                            <div class="col-md-5" id="error_self_up_rate">
                                <div class="input-group m-b">
                                    <input type="text" id="self_up_rate" name="self_up_rate" class="form-control"
                                           value="${rate.self_up_rate}"
                                           onkeyup="this.value=this.value.replace(/[^\d.]/g,'')"/>
                                    <span class="input-group-addon">%</span>
                                </div>
                                <label class="control-label" for="self_up_rate"></label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label">二级上级佣金比例：<span
                                    style="color: red;"><em>*</em></span></label>
                            <div class="col-md-5" id="error_second_up_rate">
                                <div class="input-group m-b">
                                    <input type="text" id="second_up_rate" name="second_up_rate" class="form-control"
                                           value="${rate.second_up_rate}"
                                           onkeyup="this.value=this.value.replace(/[^\d.]/g,'')"/>
                                    <span class="input-group-addon">%</span>
                                </div>
                                <label class="control-label" for="second_up_rate"></label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label">三级上级佣金比例：<span
                                    style="color: red;"><em>*</em></span></label>
                            <div class="col-md-5" id="error_third_up_rate">
                                <div class="input-group m-b">
                                    <input type="text" id="third_up_rate" name="third_up_rate" class="form-control"
                                           value="${rate.third_up_rate}"
                                           onkeyup="this.value=this.value.replace(/[^\d.]/g,'')"/>
                                    <span class="input-group-addon">%</span>
                                </div>
                                <label class="control-label" for="third_up_rate"></label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label">是否启用分销内购：<i class="fa fa-question-circle"
                                                                              onmouseout="layer.closeAll();"
                                                                              onmouseover="layer.tips('启用分销内购后，分销商购买商品自己可以拿一级佣金，自己的上级拿二级佣金；未启用时，分销商购买商品时自己是拿不到佣金的，自己的上级可以拿一级佣金。', this, {tips: [1, '#3595CC'],time: 0});"></i></label>
                            <div class="col-md-5" id="error_self_buy_rate">
                                <input id="self_buy_rate" type="checkbox" [#if rate.self_buy_rate] checked="checked" [/#if]
                                class="i-checks" value="${rate.self_buy_rate}"/>
                                <label class="control-label" for="self_buy_rate"></label>
                            </div>
                        </div>
                    </div>
                    <div class="panel-default">
                        <div class="panel-body" align="center">
                            <button type="button" onclick="saveRate();" class="btn btn-success btn-sm">保存</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <div class="col-sm-3">
            <div class="wrapper wrapper-content project-manager">
                <h4>帮助说明</h4>
                <ol>
                    <li>直属上级佣金比例：分销商推荐买家购买后能拿到的佣金比例。</li>
                    <li>二级上级佣金比例：分销商推荐买家购买后，分销商的上级分销商能拿到的佣金比例</li>
                    <li>三级上级佣金比例：分销商推荐买家购买后，分销商上级的上级能拿到的佣金比例</li>
                    <li>启用分销内购后，分销商购买商品自己可以拿一级佣金，自己的上级拿二级佣金；
                        未启用时，分销商购买商品时自己是拿不到佣金的，自己的上级可以拿一级佣金。
                    </li>
                </ol>
            </div>
        </div>
    </div>
</div>
[#include "/includes/footer.html" /]
<script type="text/javascript">
    function saveRate() {
        var params = {}, error = {};
        var self_up_rate = $("#self_up_rate").val(), second_up_rate = $("#second_up_rate").val(),
            third_up_rate = $("#third_up_rate").val(), self_buy_rate = $("#self_buy_rate").is(":checked");
        if ($.trim(self_up_rate) == "") {
            error.error_self_up_rate = "直属上级佣金比例不能为空";
        } else {
            error.error_self_up_rate = "";
            params.self_up_rate = $.trim(self_up_rate);
        }
        if ($.trim(second_up_rate) == "") {
            error.error_second_up_rate = "二级上级佣金比例不能为空";
        } else {
            error.error_second_up_rate = "";
            params.second_up_rate = $.trim(second_up_rate);
        }
        if ($.trim(third_up_rate) == "") {
            error.error_third_up_rate = "三级上级佣金比例不能为空";
        } else {
            error.error_third_up_rate = "";
            params.third_up_rate = $.trim(third_up_rate);
        }
        params.self_buy_rate = self_buy_rate;
        params.id = $("#rate_id").val();
        var hasError = false;
        for (var key in error) {
            if (error[key] != "") {
                if (!hasError) hasError = true;
                $("#" + key).addClass("has-error");
                $("#" + key).find("label").text(error[key]);
            } else {
                $("#" + key).removeClass("has-error");
                $("#" + key).find("label").empty();
            }
        }
        //主表信息不完整，返回
        if (hasError) return false;
        $("#rateForm").mask("正在保存...");
        $.post(obz.ctx + "/commission/saveRate", params, function (json) {
            if (json.code != 200) {
                obz.error(json.msg, function () {
                    $("#rateForm").unmask();
                });
            } else {
                obz.msg('保存成功', function () {
                    $("#rateForm").unmask();
                    location.reload();
                });
            }
        }, "json");
    }
</script>
<script type="text/javascript">
    Template.init("#menu-commission");
</script>
</body>
</html>